//
//  MHComicPictureCell.m
//  ManHua
//
//  Created by 赵永泉 on 15/10/27.
//  Copyright © 2015年 蓝欧科技. All rights reserved.
//

#import "MHComicPictureCell.h"
#import <UIImageView+WebCache.h>
#import <SDWebImageManager.h>

@interface MHComicPictureCell ()<UIScrollViewDelegate>
@property (nonatomic, strong) UIImageView *picture;
@property (nonatomic, strong) UILabel *number;

@end

@implementation MHComicPictureCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor lightGrayColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        self.picture = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        self.picture.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:self.picture];
        
        self.number = [[UILabel alloc]initWithFrame:CGRectMake(0, 5, Height, Width)];
        self.number.textColor = [UIColor grayColor];
        self.number.font = [UIFont systemFontOfSize:30];
        [self.contentView addSubview:self.number];
        
        [self bringSubviewToFront:self.picture];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showAssistView)];
        [self addGestureRecognizer:tap];
    }
    return self;
}

- (void)setPictureNum:(NSString *)pictureNum
{
    _pictureNum = pictureNum;
    self.number.text = pictureNum;
}

- (void)setPictureHeight:(MHPisctureHeight *)pictureHeight
{
    _pictureHeight = pictureHeight;
    self.picture.frame = CGRectMake(0, 5, Height, pictureHeight.pictureHeight);
    self.picture.image = pictureHeight.picture;
//    NSString *picturURL = pictureHeight.pictureUrl;
//    for(int i = 0; i< [picturURL length]; i++){
//        int a = [picturURL characterAtIndex:i];
//        if( a > 0x4e00 && a < 0x9fff)
//        {
//            picturURL = [picturURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//            break;
//        }
//    }
//    NSURL *url = [NSURL URLWithString:picturURL];
//    self.number.text = self.pictureNum;
//    __weak MHComicPictureCell *test = self;
//    SDWebImageManager *manager = [[SDWebImageManager alloc]init];
//    [manager downloadImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
//        test.picture.frame = CGRectMake(0, 0, Height, image.size.height / image.size.width * Width);
//        test.picture.image = image;
//        test.pictureHeight.pictureHeight = image.size.height / image.size.width * Width;
//        NSLog(@"%f", image.size.height / image.size.width * Width);
////        if (test.reloadCellBlock != nil) {
////            test.reloadCellBlock();
////        }
//    }];
////    [self.picture sd_setImageWithURL:url];
}

- (void)showAssistView
{
    if (self.showAssistViewBlock != nil) {
        self.showAssistViewBlock();
    }
}


@end
